<?php
declare(strict_types=1);

namespace WebApp\lib\app;

use stdClass;

/**
 * Class CliApp
 * @package WebApp\lib\app
 */
class CliApp extends AbstractApp
{
    /**
     * CliApp constructor.
     * @param array $get
     * @param array $post
     */
    public function __construct(&$get=[], &$post=[])
    {
        $request = new stdClass();
        $response = new stdClass();
        $request->get = $get ? $get:$this->initGet();
        $request->post = $post ? $post:$this->initPost();
        $request->cookie = [];
        $request->server = &$GLOBALS;
        parent::__construct($request, $response);
    }

    /**
     * @return array
     */
    private function initGet(){
        $get = [];
        global $argv;
        $uri = $argv[1];
        $getString = explode('?', $uri);
        $getArr = explode('&', $getString);
        foreach ($getArr as $item){
            $tmp = explode('=', $item);
            if(count($tmp) === 2){
                $get[$tmp[0]] = $tmp[1];
            }
        }
        return $get;
    }

    /**
     * @return array
     */
    private function initPost(){
        return [];
    }
}